package com.cyys.modules.system.model.user;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.cyys.common.utils.StringUtil;
import com.cyys.common.validate.Edit;
import com.cyys.common.validate.Insert;
import com.cyys.modules.core.model.CoreBean;
import com.cyys.modules.core.sysParam.OrgUtil;
import com.cyys.modules.core.sysParam.SystemConfigureUtil;
import com.cyys.modules.core.sysParam.SystemConstants;
import com.cyys.modules.system.model.org.Org;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;

import javax.validation.constraints.NotBlank;
import java.util.List;

@Data
@TableName("sys_role")
public class Role extends CoreBean {

	@NotBlank(message = "角色名称不能为空",groups = {Edit.class, Insert.class})
	private String roleName;  //角色名称
	
	private String roleDesp;  //角色描述

	@TableField(exist = false)
	@JsonIgnore
	private List<Menu> menuList;   //权限

	@JsonIgnore
	private String roleType;  //角色类型

	private String orgId; //所属机构

	@JsonIgnore
	public String getOrgName(){
		Boolean mutiOrg = Boolean.valueOf(SystemConfigureUtil.get(SystemConstants.MUTI_ORG));
		if(mutiOrg) {
			if (StringUtil.isEmpty(orgId)) {
				return "";
			} else if (!orgId.equals("0")) {
				return OrgUtil.get(orgId).getName();
			} else if (orgId.equals("0")) {
				return "顶级节点";
			}
		}
		return "";
	}

	@JsonIgnore
	public Org getOrg(){
		Boolean mutiOrg = Boolean.valueOf(SystemConfigureUtil.get(SystemConstants.MUTI_ORG));
		if(mutiOrg) {
			if (StringUtil.isNotEmpty(orgId)) {
				return OrgUtil.get(orgId);
			}
		}
		return null;
	}

}
